<?php
/* @var $this yii\web\View */
/* @var $model backend\models\Goods */
/* @var $models backend\models\Goods */
/* @var $search backend\models\Goods */

use backend\models\ArticleCategory;
use backend\models\Goods;
use kartik\select2\Select2;
use yii\bootstrap\ActiveForm;
use yii\bootstrap\Html;
use yii\helpers\Url;
use yii\web\JsExpression;
use yii\widgets\LinkPager;

$this->title = "商品列表";


$this->params['breadcrumbs'][]=$this->title;


$this->params['breadcrumbs'][]=[
    'label'=>'添加商品',
    'url'=>['goods/add'],
    'options'=>['class'=>'btn btn-default btn-warning']
];
$this->params['breadcrumbs'][]=[
    'label'=>'回收站',
    'url'=>['goods/recycle-bin'],
    'options'=>['class'=>'btn btn-warnging'],
];

$data = [2 => 'widget', 3 => 'dropDownList', 4 => 'yii2'];



?>



<div class="container table-responsive">
    <div class="form-group ">
<!--        /搜索功能-->
         <?php $form=ActiveForm::begin([
                 'layout' => 'horizontal',
                 'method' => 'get',
                 'action' => Url::to(['goods/list']),
                 'options'=>[
                         'class'=>'form-inline  well  ',
                        'style'=>'min-height:75px',
                 ],
                'fieldConfig' => [
                    'template' => "\n<div class=\"col-lg-2\">{input}</div>\n",
                    'labelOptions' => ['class' => 'col-lg-1 control-label'],
             ],
         ])?>
        <div class="inline col-lg-2 form-group" >
        <?=Select2::widget([
            'name'=>'id',
            'options' => [
                    'placeholder' => '商品 ／ 货号 ...',
                'multiple'=>true ,
//                'class'=>'input-sm search-query ',
            ],
            'pluginOptions' => [
                'placeholder' => 'search sn or name ...',
                'allowClear' => true,
                'language' => [
                    'errorLoading' => new JsExpression("function () { return 'Waiting...'; }"),
                ],
                'ajax' => [
                    'url' => Url::to(['goods/search-title']),
                    'dataType' => 'json',
                    'data' => new JsExpression('function(params) { return {q:params.term}; }')
                ],
                'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
                'templateResult' => new JsExpression('function(res) { return res.text; }'),
                'templateSelection' => new JsExpression('function (res) { 
                    $("#search-goods-name").val(res.text);
                    $("#search-sn").val(res.sn);
                }'),
            ],
        ]);?>
        </div>
        <?=$form->field($search,'goods_name', ['inputOptions' => ['placeholder' => '商品名称',],])->textInput(['id'=>'search-goods-name'])->label(false);?>
        <?=$form->field($search,'goods_sn',[ 'inputOptions' => [ 'placeholder' => '商品货号',],])->textInput(['id'=>'search-sn'])->label(false);?>
        <?=$form->field($search,'goods_status')->inline()->dropDownList(Goods::$statusValue)->label(false);?>
        <?=$form->field($search,'gasp', ['inputOptions' => ['placeholder' => 'max-price',], ])->textInput()->label(false);?>
        <?=$form->field($search,'gisp',['inputOptions' => ['placeholder' => 'min-price',],])->label(false);?>
        <?=Html::submitButton('<span class="glyphicon gly glyphicon-search"></span>',['class'=>'btn btn-default searchBar'])?>
        <?php ActiveForm::end();?>
    </div>

    <table class="table table-hover ">
        <tr>
            <td>货号</td>
            <td width="20%">名称</td>
            <td>本店价格</td>
            <td>状态</td>
            <td>库存</td>
            <td>更新时间</td>
            <td>操作</td>
        </tr>
        <?php foreach($models as $model): ?>
            <tr>
                <td><?=$model->sn?></td>
                <td><?=$model->name?></td>
                <td><?=$model->shop_price?></td>
                <td><?=Goods::$statusValue[$model->status]?></td>
                <td><?=$model->stock?></td>
                <td><?=date('y-m-d H:m:s',$model->update_at)?></td>
                <td>
                    <?=Html::a('<span class="glyphicon glyphicon-edit"></span>',['goods/edit','id'=>$model->id],['class'=>'btn btn-info btn-sm'])?>
                    <?=Html::a('<span class="glyphicon glyphicon-picture"></span>',['goods/add-gallery','goods_id'=>$model->id],['class'=>'btn btn-info btn-sm'])?>
                    <?=Html::a('<span class="glyphicon glyphicon-eye-open"></span>',['goods/show','id'=>$model->id],['class'=>'btn btn-info btn-sm'])?>
                    <?=Html::a('<span class="glyphicon glyphicon-trash"></span>',['goods/del','id'=>$model->id],[
                        'class'=>'btn btn-danger btn-sm',
                        'data'=>[
                            'confirm'=>'确认删除!',
                            'method'=>'post',
                        ],
                    ])?>
                </td>
            </tr>
        <?php endforeach;?>
    </table>

    <?=LinkPager::widget([
        'pagination'=>$pager,
        'prevPageLabel'=>'上一页',
        'nextPageLabel'=>'下一页',
    ])?>


</div>

<?php
/*
 *    $form = ActiveForm::begin();

<?=$form->field(new Goods(), 'name' )->widget(Select2::classname(), [
    'name'=>'name',
    'options' => ['placeholder' => '请输入商品名称 ...','multiple'=>true ],
    'pluginOptions' => [
        'placeholder' => 'search ...',
        'allowClear' => true,
        'language' => [
            'errorLoading' => new JsExpression("function () { return 'Waiting...'; }"),
        ],
        'ajax' => [
            'url' => Url::to(['goods/search-title']),
            'dataType' => 'json',
            'data' => new JsExpression('function(params) { return {q:params.term}; }')
        ],
        'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
        'templateResult' => new JsExpression('function(res) { return res.text; }'),
        'templateSelection' => new JsExpression('function (res) { return res.text; }'),
    ],
]);

<?=Html::submitButton('搜索',['class'=>'btn btn-info']);

    ActiveForm::end();
 */



?>


